<template>
  <div class="find">
    <!-- 标题 -->
    <van-nav-bar class="title" title="发现" :fixed="true"> </van-nav-bar>
    <!-- 内容 -->
    <div class="main">
      <!-- 面试技巧 -->
      <div class="interview box">
        <van-cell
          title="面试技巧"
          is-link
          value="查看更多"
          @click="$router.push('/interviewList')"
        />
        <!-- 骨架屏 -->
        <div v-if="interviewList.length === 0">
          <van-skeleton
            class="item"
            title
            :row="3"
            v-for="index in 3"
            :key="index"
          />
        </div>
        <!-- 骨架屏结束 -->
        <div
          class="item"
          v-for="(item, index) in interviewList"
          :key="index"
          @click="$router.push('/interviewDetail/' + item.id)"
        >
          <div class="content">
            <p>{{ item.title }}</p>
            <div class="info">
              <div class="time">
                <span>{{ item.created_at | dateStyleOne }}</span>
              </div>
              <div class="flex"></div>
              <div class="right">
                <van-icon name="eye-o" />
                <span>{{ item.read }}</span>
                <van-icon
                  name="good-job-o"
                  :class="{ red: starArticles.includes(item.id) }"
                />
                <!-- :class="{ red: starArticles.includes(item.id) }" -->
                <!-- {{ starArticles }} -->
                <span>{{ item.star }}</span>
              </div>
            </div>
          </div>
          <img :src="baseUrl + item.cover" alt="" />
        </div>
      </div>
      <!-- 市场数据 -->
      <div class="marketData box">
        <van-cell
          title="市场数据"
          is-link
          value="查看更多"
          @click="$router.push('/chart')"
        />
        <div class="keyword" v-if="hotJob">
          <span>{{ hotJob.city }}</span>
          <span>{{ hotJob.position }}</span>
        </div>
        <!-- 骨架屏 -->
        <div v-if="!hotJob">
          <van-skeleton class="item" title :row="3" />
        </div>
        <!-- 骨架屏结束 -->
        <div class="data" v-if="hotJob">
          <div
            class="item"
            v-for="(item, index) in hotJob.yearSalary"
            :key="index"
            v-show="index < show"
          >
            <span>{{ item.year }}</span>
            <div class="chart">
              <div class="salary" :style="{ width: item.proportion + '%' }">
                ¥{{ item.salary }}
              </div>
            </div>
            <div class="info">
              <i
                v-if="item.percent < 0"
                class="iconfont iconicon_xiajiang"
                style="color:#fe6d67"
              ></i>
              <i
                v-if="item.percent > 0"
                class="iconfont iconicon_shangsheng"
                style="color:#60d183"
              ></i>
              <div class="flex"></div>
              <span v-if="item.percent">{{ item.percent }}%</span>
              <span v-if="item.percent === 0">0</span>
            </div>
          </div>
          <div class="btn" @click="show = 4" v-if="show === 10">
            收起显示
            <van-icon name="arrow-up" />
          </div>
          <div class="btn" @click="show = 10" v-if="show === 4">
            显示更多
            <van-icon name="arrow-down" />
          </div>
        </div>
      </div>
      <!-- 面经分享 -->
      <div class="experience box">
        <van-cell
          title="面经分享"
          is-link
          value="查看更多"
          @click="$router.push('/experienceList')"
        />
        <!-- 骨架屏 -->
        <div v-if="moreaufaceList.length === 0">
          <van-skeleton
            class="item"
            title
            :row="3"
            v-for="index in 3"
            :key="index"
          />
        </div>
        <!-- 骨架屏结束 -->
        <div
          class="item"
          v-for="(item, index) in moreaufaceList"
          :key="index"
          @click="$router.push('/experienceDetail/' + item.id)"
        >
          <div class="art_title">{{ item.title }}</div>
          <p>
            {{ item.content.substring(0, 60) }}
          </p>
          <div class="info">
            <div class="user">
              <img :src="baseUrl + item.author.avatar" />
              <span>{{ item.author.nickname }}</span>
            </div>
            <div class="flex"></div>
            <div class="right">
              <span>{{ item.created_at | dateStyleOne }}</span>
              <van-icon name="comment-o" />
              <span>{{ item.read }}</span>
              <van-icon
                name="good-job-o"
                :class="{ red: starArticles.includes(item.id) }"
              />
              <!-- :class="{ red: starArticles.includes(item.id) }" -->
              <!-- {{ starArticles }} -->
              <span>{{ item.star }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 导入接口
import {
  apiInterviewingList,
  apiHotJob,
  apiExperienceList
} from '@/api/find.js'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL,
      interviewList: [], // 面试技巧列表
      hotJob: null, // 热门职位
      show: 4,
      moreaufaceList: [], // 面经列表
      starArticles: [] // 文章点赞列表
    }
  },
  async mounted () {
    // 获取用户点赞列表
    if (this.$store.state.userInfo.starArticles) {
      this.starArticles = this.$store.state.userInfo.starArticles
    }
    // console.log(this.$store.state.userInfo.starArticles)
    this.$toast.loading({
      message: '加载中...',
      forbidClick: true
    })
    // 面试技巧
    apiInterviewingList({ start: 0, limit: 3, q: '' }).then(res => {
      this.interviewList = res.data.list
    })

    // 热门职位数据
    apiHotJob().then(res2 => {
      var obj = JSON.parse(JSON.stringify(res2.data))
      obj.yearSalary = obj.yearSalary.reverse() // 翻转数据
      var sampleArr = obj.yearSalary.map(item => {
        return item.sample
      })
      sampleArr = sampleArr.sort(function (a, b) {
        return b - a
      })
      const maxdata = sampleArr[0]
      obj.yearSalary.forEach(item => {
        item.proportion = (item.sample * 100) / maxdata
      })
      this.hotJob = obj
    })

    // 面经列表
    apiExperienceList({ start: 0, limit: 3, q: '' }).then(res3 => {
      this.moreaufaceList = res3.data.list
    })
  }
}
</script>

<style lang="less" scoped>
.find {
  // margin-top: 46px;
  background-color: #f9f9f9;
  .red {
    color: red !important;
  }
  .title {
    background-color: #ca0131;
    /deep/.van-nav-bar__title {
      color: #fff;
    }
  }
  .main {
    margin: 46px 0 50px;
    .box {
      background-color: #fff;
      margin-bottom: 10px;
      padding: 0 15px;
      /* 取消单元格左右padding */
      /deep/ .van-cell--clickable {
        padding: 10px 0;
      }
      .info {
        display: flex;
        height: 20px;
        .flex {
          flex: 1;
        }
        .van-icon {
          line-height: 20px;
          font-size: 14px;
        }
        span {
          vertical-align: middle;
          line-height: 20px;
          font-size: 12px;
          padding: 0 7px;
        }
      }
    }
    /* 面试分享 */
    .interview {
      .item {
        display: flex;
        align-items: center;
        height: 125px;
        padding-top: 10px;
        padding-bottom: 25px;
        .content {
          height: 100%;
          width: 65%;
          padding-right: 10px;
          p {
            margin: 0;
            height: 70px;
            font-size: 16px;
          }
        }
        img {
          width: 35%;
          height: 90px;
        }
      }
    }
    /* 市场数据 */
    .marketData {
      .keyword {
        padding: 15px 0;
        span {
          font-size: 16px;
          padding: 4px 7px;
          border-radius: 10px;
          color: #545671;
          background-color: #eceaea;
          margin-right: 15px;
        }
      }
      .data {
        padding-bottom: 20px;
        padding-right: 15px;
        .item {
          margin-bottom: 20px;
          font-size: 14px;
          display: flex;
          align-items: center;
          /deep/ .iconfont {
            font-size: 16px !important;
            margin-right: 10px;
          }
          .chart {
            margin: 0 10px;
            height: 12px;
            background-color: #ebdfdf;
            border-radius: 6px;
            flex: 1;
            .salary {
              line-height: 12px;
              padding-right: 7px;
              color: #fff;
              font-size: 12px;
              // width: 85%;
              text-align: right;
              height: 100%;
              background-color: #fe6d67;
              border-radius: 6px;
            }
          }
          .info {
            width: 47px;
          }
        }
        .btn {
          font-size: 16px;
          color: #545671;
          text-align: center;
        }
      }
    }
    /* 面经分享 */
    .experience {
      margin: 0;
      .item {
        height: 140px;
        padding-top: 10px;
        padding-bottom: 25px;
        .art_title {
          height: 30px;
          font-size: 18px;
        }
        p {
          height: 55px;
          margin: 0;
          line-height: 27px;
          font-size: 14px;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        .info {
          .user {
            img {
              vertical-align: middle;
              width: 22px;
              height: 22px;
              border-radius: 50%;
            }
          }
        }
      }
    }
  }
}
</style>
